package ic.symbols;

import ic.ast.decl.Parameter;
import ic.ast.decl.Type;
import ic.ast.stmt.LocalVariable;
import ic.types.TypeTable;

/**
 * Created with IntelliJ IDEA.
 * User: Matan
 * Date: 12/10/13
 * Time: 11:25 AM
 */
public class VarSymbol extends Symbol {

    Type type;
    boolean isParam;
    int defineStep = 0;
    int initStep = Integer.MAX_VALUE;
    int column = -1;


    /**
     * constructors
     */

    public VarSymbol(LocalVariable lv) throws Exception {
        super(lv.getName(), Kind.VARIABLE, lv.getLine());
        this.isParam = false;
        this.type = TypeTable.getType(lv.getType());
        //this.column = lv.getColumn(); // TODO
    }

    public VarSymbol(Parameter f) throws Exception {
        super(f.getName(), Kind.VARIABLE, f.getLine());
        this.isParam = true;
        this.type = TypeTable.getType(f.getType());
    }

    /**
     * getters and setters
     */

    public int getDefineStep() {
        return defineStep;
    }

    public void setDefineStep(int step) {
        defineStep = step;
    }

    public int getInitStep() {
        return initStep;
    }

    public void setInitStep(int step) {
        initStep = step;
    }

    public boolean isParam() {
        return this.isParam;
    }

    public Type getType() {
        return this.type;
    }

    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append(isParam() ? "Parameter:  " : "Local variable:  ");
        str.append(getID());
        str.append(" : ");
        str.append(getType());
        return str.toString();
    }

    public boolean equals(Object other) {
        return this == other;
    }

    public int getColumn() {
        return column;
    }
}

